import React from "react";

export default function PostDetail(props: any) {
  const { post } = props;
  console.log(post);
  if (!post) return <p>加载中。。。</p>;
  return (
    <>
      <ul>
        <li>{post.id}</li>
        <li>{post.title}</li>
        <li>{post.body}</li>
      </ul>
    </>
  );
}

export async function getServerSideProps(context: any) {
  const { params } = context;
  const id = params.pid;
  const post = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`);
  const data = await post.json();
  return {
    props: {
      post: data,
    },
  };
}
